/**
 * 自定义轻提示
 * @returns {string | undefined}
 * @param title
 * @param icon
 * @param duration
 */
export function myToast(title, icon = 'none', duration = 2000) {
  uni.showToast({ title, icon, duration }).then()
}

/**
 * Date格式转为指定格式
 * @returns {string | undefined}
 * @param date
 * @param format
 */
export function formatDate(date, format = 'yyyy-MM-dd hh:mm:ss') {
  if(!date) { return }

  const year = date.getFullYear()
  const month = String(date.getMonth() + 1).padStart(2, '0')
  const day = String(date.getDate()).padStart(2, '0')
  const hours = String(date.getHours()).padStart(2, '0')
  const minutes = String(date.getMinutes()).padStart(2, '0')
  const seconds = String(date.getSeconds()).padStart(2, '0')

  let formattedDate = format
  formattedDate = formattedDate.replace('yyyy', year)
  formattedDate = formattedDate.replace('MM', month)
  formattedDate = formattedDate.replace('dd', day)
  formattedDate = formattedDate.replace('hh', hours)
  formattedDate = formattedDate.replace('mm', minutes)
  formattedDate = formattedDate.replace('ss', seconds)

  return formattedDate
}
